package cn.duhengkui.national.valuelist.example.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.duhengkui.national.valuelist.example.entity.Bookinfo;
import cn.duhengkui.national.valuelist.example.service.BookInfoService;
import cn.duhengkui.national.valuelist.example.vo.MyBook;

@RestController
public class BookInfoController {
	
	@Autowired
	private BookInfoService bookInfoServiceImpl;
	
	@GetMapping("/myBooks")
	public @ResponseBody List<MyBook> getBookList(){
		return bookInfoServiceImpl.getMyBooks();
	}
	
	@PostMapping("/saveBook")
	public @ResponseBody String saveBook(@RequestParam("auther")String auther,@RequestParam("bookName")String bookName,@RequestParam("price")Double price){
		try{
			Bookinfo bookInfo = new Bookinfo();
			bookInfo.setBookAuthor(auther);
			bookInfo.setBookName(bookName);
			bookInfo.setBookPrice(price);
			bookInfoServiceImpl.save(bookInfo);
			return "成功";
		}catch(Exception e){
			return "失败";
		}
	}
	
}
